package com.doupi.partner.manager;

import com.doupi.partner.model.Profit;
import com.doupi.partner.service.AdministratorService;
import com.doupi.partner.service.dto.ProfitDto;
import com.doupi.partner.util.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 收益manager
 *
 * @author Alvin Wang
 * @version 1.0.0 @ 2017-04-17
 */
@Component
public class ProfitManager {
	private final AdministratorService administratorService;

	@Autowired
	public ProfitManager(AdministratorService administratorService) {
		this.administratorService = administratorService;
	}

	/**
	 * 将List<UserRelation>转为 List<UserRelationDto> lists
	 */
	public List<Profit> convertProfitListToDtoList(List<Profit> records) {
		List<Profit> lists = new ArrayList<>();
		for (Profit profit : records) {
			ProfitDto profitDto = new ProfitDto();
			ObjectUtils.copyProperties(profitDto, profit);
			profitDto.setAdministrator(administratorService.selectByPrimaryKey(profit.getAdministratorId()));
			profitDto.setPartnerAdministrator(administratorService.selectByPrimaryKey(profit.getPartnerAdministratorId()));
			profitDto.setBusinessAdministrator(administratorService.selectByPrimaryKey(profit.getBusinessAdministratorId()));
			lists.add(profitDto);
		}
		return lists;
	}
}
